/**
 * @description 持仓分析
 * @author wangjianjun
 */

import React, { PureComponent } from 'react';
import { TableC } from '../../../../comps';
import { message } from 'antd';
import 'moment/locale/zh-cn';
export default class PositionAnalysis extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {}

  //触发回填质押券
  addNewPledgeBond = (record) => {
    const { quotationType, settlementDate, repoRate, orderSide } = this.props;
    if (orderSide == '融券回购' || orderSide == '1') {
      message.warning('融券回购时无法回填质押券！');
      return;
    }
    if (quotationType != '1') {
      message.warning('此报价类型不支持点击回填');
      return;
    }

    if (quotationType && settlementDate && repoRate) {
      this.props.addNewPledgeBond(record);
    } else {
      message.warning('请填写指令下达部分的 "产品,组合,交易所,报价类型,回购利率,到期结算日"的数据');
      return;
    }
  };

  render() {
    const { columns, dataSource } = this.props;
    let widths = '14%';
    if (this.props.tradeBook == '1') {
      widths = '130px';
    }
    if (columns && columns.length > 0) {
      columns.map((item, key) => {
        if (item.key == 'pledgeBondCode') {
          item.width = widths;
          item.fixed = 'left';
          item.render = (text, record) => {
            return (
              <span style={{ color: '#4D86FF', cursor: 'pointer ' }} onDoubleClick={() => this.addNewPledgeBond(record)}>
                {text}{' '}
              </span>
            );
          };
        }

        if (item.key == '"pledgeBondName"') {
          item.width = '14%';
        }

        if (item.key == 'canUse') {
          item.width = '14%';
          item.type = 'number';
        }

        if (item.key == 'dueDate') {
          item.width = '14%';
        }

        if (item.key == 'nextPaymentDate') {
          item.width = '14%';
        }

        if (item.key == 'externalRating') {
          item.width = '14%';
        }

        if (item.key == 'remainingDenomination') {
          item.width = '16%';
          item.type = 'money';
        }
      });
    }

    return (
      <div>
        <TableC noDataHeight="165px" columns={columns} dataSource={dataSource} hidePage={true} scroll={{ x: 850, y: 350 }} />
      </div>
    );
  }
}
